import classNames from 'classnames';
import { Component } from 'react';
import { StringUtils } from 'xo-web-base';
import styles from './index.less';

interface RichTextProps {
  className?: string;
  /**
   * 内容
   */
  content?: string;
}

/**
 * 富文本组件
 *
 * 自带xss过滤
 * 自动限制图片最大宽度
 */
class RichText extends Component<RichTextProps> {
  render() {
    const { className, content } = this.props;
    return (
      <div
        className={classNames(styles.rich_text, className)}
        dangerouslySetInnerHTML={{ __html: StringUtils.xssFilter(content) }}
      />
    );
  }
}

export default RichText;
